{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Oil and Gas Visualization/Dashboard"
      ],
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Import required libraries"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import plotly.plotly as py\n",
        "import plotly.offline as pyo\n",
        "import cufflinks as cf"
      ],
      "outputs": [],
      "execution_count": 62,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Import New York State dataset"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "df = pd.read_csv('data/wellspublic.csv', low_memory=False)\n",
        "df.shape"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 63,
          "data": {
            "text/plain": [
              "(41716, 52)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 63,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.columns"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 64,
          "data": {
            "text/plain": [
              "Index(['API_WellNo', 'Cnty', 'Hole', 'SideTrck', 'Completion', 'Well_Name',\n",
              "       'Company_name', 'Operator_number', 'Well_Type', 'Map_Symbol',\n",
              "       'Well_Status', 'Date_Status', 'Date_Permit_Application',\n",
              "       'Permit_Issued', 'Date_Spudded', 'Date_Total_Depth',\n",
              "       'Date_Well_Completed', 'Date_well_plugged', 'Date_well_confidential',\n",
              "       'confid', 'town', 'quad', 'quadsec', 'Producing_name',\n",
              "       'Producing_formation', 'Financial_security', 'Slant', 'County',\n",
              "       'Region', 'State_lease', 'Proposed_depth', 'Surface_location',\n",
              "       'Surface_Longitude', 'Surface_latitude', 'Bottom_hole_location',\n",
              "       'Bottom_hole_longitude', 'Bottom_hole_latitude', 'True_vertical_depth',\n",
              "       'Measured_depth', 'Kickoff', 'DrilledDepth', 'Elevation',\n",
              "       'Original_well_type', 'Permit_Fee', 'Objective_formation', 'Depth_Fee',\n",
              "       'Spacing', 'Spacing_Acres', 'Integration', 'Dt_Hearing', 'Dt_Mod',\n",
              "       'LINK'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 64,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Make scattermapbox map"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "types = dict(\n",
        "    BR = 'Brine',\n",
        "    Confidential = 'Confidential',\n",
        "    DH = 'Dry Hole',\n",
        "    DS = 'Disposal',\n",
        "    DW = 'Dry Wildcat',\n",
        "    GD = 'Gas Development',\n",
        "    GE = 'Gas Extension',\n",
        "    GW = 'Gas Wildcat',\n",
        "    IG = 'Gas Injection Well',\n",
        "    IW = 'Enhanced Oil Recovery - Injection',\n",
        "    LP = 'Liquefied Petroleum Gas Storage',\n",
        "    MB = 'Monitoring Brine',\n",
        "    MM = 'Monitoring Miscellaneous',\n",
        "    MS = 'Monitoring Storage',\n",
        "    NL = 'Not Listed',\n",
        "    OB = 'Observation Well',\n",
        "    OD = 'Oil Development',\n",
        "    OE = 'Oil Extension',\n",
        "    OW = 'Oil Wildcat',\n",
        "    SG = 'Stratigraphic',\n",
        "    ST = 'Storage',\n",
        "    TH = 'Geothermal',\n",
        "    UN = 'Unknown',\n",
        ")\n",
        "\n",
        "traces = []\n",
        "for well, df in df.groupby('Well_Type'):\n",
        "    trace = dict(\n",
        "        type = 'scattermapbox',\n",
        "        lon = df['Surface_Longitude'],\n",
        "        lat = df['Surface_latitude'],\n",
        "        text = df['Well_Name'],\n",
        "        name = types[well],\n",
        "        marker = dict(\n",
        "            size = 4,\n",
        "            opacity = 0.6,\n",
        "        )\n",
        "    )\n",
        "    traces.append(trace)\n",
        "\n",
        "# trace = dict(\n",
        "#     type = 'scattermapbox',\n",
        "#     lon = df['Surface_Longitude'],\n",
        "#     lat = df['Surface_latitude'],\n",
        "#     name = df['Well_Name'],\n",
        "# )\n",
        "\n# traces = [trace]"
      ],
      "outputs": [],
      "execution_count": 65,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "mapbox_access_token = 'pk.eyJ1IjoiamFja2x1byIsImEiOiJjaXhzYTB0bHcwOHNoMnFtOWZ3YWdreDB3In0.pjROwb9_CEuyKPE-x0lRUw'\n",
        "\n",
        "layout = dict(\n",
        "\n",
        "    title = \"New York Oil and Gas map\",\n",
        "\n",
        "    # GENERAL LAYOUT\n",
        "    width = 1280,\n",
        "    height = 720,\n",
        "    autosize = True,\n",
        "    font = dict(\n",
        "        family = \"Overpass\",\n",
        "        size = 12,\n",
        "        color = '#CCCCCC',\n",
        "    ),\n",
        "    margin = dict(\n",
        "        t = 80,\n",
        "        l = 40,\n",
        "        b = 40,\n",
        "        r = 120,\n",
        "        pad = 0, \n",
        "    ),\n",
        "\n",
        "    # OPTIONAL\n",
        "    hovermode = \"closest\",\n",
        "    \n",
        "    # COLOR THEME\n",
        "    plot_bgcolor = \"#191A1A\",\n",
        "    paper_bgcolor = \"#020202\",\n",
        "    \n",
        "    # LEGEND\n",
        "    legend = dict(\n",
        "        x = 1.02,\n",
        "        y = 1,\n",
        "        font = dict(size = 10),\n",
        "    ),\n",
        "\n",
        "    # MAPBOX\n",
        "    mapbox = dict(\n",
        "        accesstoken = mapbox_access_token,\n",
        "        style = \"dark\",\n",
        "        center = dict(\n",
        "            lon = -76.40,\n",
        "            lat = 42.70,\n",
        "        ),\n",
        "        zoom = 5.5,\n",
        "    ),\n",
        "\n)"
      ],
      "outputs": [],
      "execution_count": 66,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "figure = dict(data=traces, layout=layout)\n",
        "py.plot(figure, filename='Oil map')"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 68,
          "data": {
            "text/plain": [
              "'https://plot.ly/~jackluo/3594'"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 68,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.6.0",
      "mimetype": "text/x-python",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "file_extension": ".py"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}